<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>layui</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="../plugins/layui/css/layui.css" media="all">
		<script src="../plugins/layui/layui.js"></script>
		<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
	</head>

	<body>
		<script>
			layui.use('laydate', function() {
				var laydate = layui.laydate;

				//日期范围
				laydate.render({
					elem: '#test6',
					range: true
				});
			});
		</script>

		<table class="layui-hide" id="test" lay-filter="test">

			<div id="ti" style="border:0px; margin: 0px;">
				<div class="layui-inline">
					<label class="layui-form-label" style="width: 100px;margin: 5px;">选择日期范围:</label>
					<div class="layui-input-inline">
						<input class="layui-input" id="test6" type="text" placeholder=" 起始日期 - 结束日期 " style="margin: 5px;">
					</div>
				</div>
				<!--搜索选择框-->
				<div class="layui-inline">
					
          
					<select name="city" lay-verify="" lay-search style="height: 38px;width: 80px;margin-left: 2px;">
								<option value="010" selected>商品名称</option>
								<option value="021">商品Id</option>
								<option value="010">商品品牌</option>
								<option value="021">商品Id</option>
								

							</select>
				</div>

				<div class="layui-input-inline">
					<input type="text" name="title" required lay-verify="required" placeholder="请输入搜索内容" autocomplete="off" class="layui-input">
				</div>
				
				<button class="layui-btn layui-btn-normal">搜索</button>

			</div>
		</table>

		<script type="text/html" id="toolbarDemo">
			<div class="layui-btn-container">

				<button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
				<button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
				<button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
				<button class="layui-btn layui-btn-sm" lay-event="add">添加商品</button>
			</div>
		</script>

		<script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
		</script>

		<script src="//res.layui.com/layui/dist/layui.js" charset="utf-8"></script>
		<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

		<script>
			layui.use('table', function() {
				var table = layui.table;

				table.render({
					elem: '#test',
					url: '../dataset/data.json',
					toolbar: '#toolbarDemo',
					title: '商品列表',
					cols: [
						[{
							type: 'checkbox',
							fixed: 'left'
						}, {
							field: 'id',
							title: '商品ID',
							width: 80,
							fixed: 'left',
							unresize: true,
							sort: true
						}, {
							field: 'username',
							title: '商品名称',
							width: 120,
							edit: 'text'
						}, {
							field: 'email',
							title: '商品价格',
							width: 150,
							edit: 'text',
							templet: function(res) {
								return '<em>' + res.email + '</em>'
							}
						}, {
							field: 'sex',
							title: '商品图片',
							width: 150,
							edit: 'text',
							sort: true
						}, {
							field: 'city',
							title: '商品描述',
							width: 100
						}, {
							field: 'sign',
							title: '积分兑换状态',
							width: 200
						}, {
							field: 'experience',
							title: '商品积分',
							width: 150,
							sort: true
						}, {
							field: 'ip',
							title: '商品详细信息'
						}, {
							field: 'logins',
							title: '商品介绍',
							width: 100,
							sort: true
						}, {
							field: 'joinTime',
							title: '商品品牌',
							width: 120
						}, {
							fixed: 'right',
							title: '操作',
							toolbar: '#barDemo',
							width: 150
						}]
					],
					page: true
				});

				//头工具栏事件
				table.on('toolbar(test)', function(obj) {
					var checkStatus = table.checkStatus(obj.config.id);

					switch(obj.event) {
						case 'getCheckData':
							var data = checkStatus.data;
							layer.alert(JSON.stringify(data));
							break;
						case 'getCheckLength':
							var data = checkStatus.data;
							layer.msg('选中了：' + data.length + ' 个');
							break;
						case 'isAll':
							layer.msg(checkStatus.isAll ? '全选' : '未全选');
							break;
						case 'add':
							layer.msg('添加');
							layer.open({
								type: 2,
								content: 'add.html', //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
								area:['70%','70%'],
								maxmin: true
							});
							break;

					};
				});

				//监听行工具事件
				table.on('tool(test)', function(obj) {
					var data = obj.data;
					//console.log(obj)
					if(obj.event === 'del') {
						layer.confirm('真的删除行么', function(index) {
							obj.del();
							layer.close(index);
						});
					} else if(obj.event === 'edit') {
						layer.prompt({
							formType: 2,
							value: data.email
						}, function(value, index) {
							obj.update({
								email: value
							});
							layer.close(index);
						});
					}
				});
			});
		</script>

	</body>

</html>